<?php 
/**
 * ... ...
 * ... ...
 *
 */ 


JCAT_Package::ImportClass('JCAT_Controller',JCAT::PACKAGE_MVC) ;

/**
 * 控制器类 DBConnect 
 *
 * @access public
 */
class DBConnect 
	extends JCAT_Controller 
{

	/**
	 * 构造函数 
	 * 
	 * @access	public
	 * @param	$aParent	JCAT_IController	父控制器 
	 * @return	void
	 */
	public function DBConnect(JCAT_IController $aParent=null )
	{
		// 调用父类构造函数
		$this->JCAT_Controller(__CLASS__,$aParent) ;
		
		// 初始化文档、视图、子控制器 
		$this->Initialize() ;
	}

	/**
	 * 初始化文档、视图、子控制器 
	 * 
	 * @access	protected
	 * @return	void
	 */
	protected function Initialize()
	{
		//<<[UnmodifiableBlock.Start]::Message Queue::>>//

		//<<[UnmodifiableBlock.End]::Message Queue::>>// 
		
		
		$sHere = JCAT_Global::TidyPath( dirname(__FILE__) ) ;
		
		//<<[UnmodifiableBlock.Start]::Initialize Children::>>//
		// 创建并加载视图：DBConnectDlg
		JCAT_Package::ImportClass('DBConnectDlg',$sHere.'class.DBConnectDlg.php');
		$aView = new DBConnectDlg($this) ;
		$this->AddView($aView) ;
		//<<[UnmodifiableBlock.End]::Initialize Children::>>// 

		//<<[UnmodifiableBlock.Start]::Register Children Global Name::>>//

		//<<[UnmodifiableBlock.End]::Register Children Global Name::>>// 
		
		//<<[UnmodifiableBlock.Start]::Set Document To View::>>//

		//<<[UnmodifiableBlock.End]::Set Document To View::>>// 
		

		// 在此添加代码 
		// TODO ... ... 
	}

	
	/**
	 * 执行入口函数 
	 * 
	 * @access	public
	 * @param	$arrArg=array	array	参数 
	 * @return	JCAT_DB, null
	 */
	public function MainRun(array $arrArg=array())
	{
		//<<[UnmodifiableBlock.Start]::Main Run::>>//
		
		// 显示视图 DBConnectDlg
		$aView = $this->GetView('DBConnectDlg') ;
		JCAT_ASSERT::ASSERT_INSTANCE($aView,'JCAT_IView',JCAT_Language::Sentence('名为 %s 的视图未定义','DBConnectDlg')) ;
		$nResponse = $aView->DoDialog() ;
		if( $nResponse===Gtk::RESPONSE_OK )
		{
			return $this->aDB ;
		}
		else
		{
			return null ;
		}


		//<<[UnmodifiableBlock.End]::Main Run::>>// 

	}

	
	/**
	 * what's this
	 * 
	 * @access	public
	 * @return	void
	 */
	public function OnConnect()
	{
		$aView = $this->GetView('DBConnectDlg') ;
		$sDBFactory = $aView->GetUICtrlExchangeData('DBFactory') ;

		// 创建对象
		$this->aDB = new JCAT_DB($sDBFactory) ;
		
		$sDBServer = $aView->GetUICtrlExchangeData('DBServer') ;
		$sDBUser = $aView->GetUICtrlExchangeData('DBUser') ;
		$sDBPassword = $aView->GetUICtrlExchangeData('DBPassword') ;
		$sDBName = $aView->GetUICtrlExchangeData('DBName') ;
		$sMsg = '' ;

		do {
			
			$this->bIsConnected = false ;
			
			
			// 连接到服务器
			if( !$this->aDB->Connect($sDBServer,$sDBUser,$sDBPassword) )
			{
				$sError = $this->aDB->GetError() ;
				$sMsg = JCAT_Language::Sentence("连接失败：\r\n\r\n%s",$sError) ;
				break ;
			}
	
			// 选择数据库
			if( $this->aDB->SelectDB($sDBName)===false )
			{
				$sError = $this->aDB->GetError() ;
				$sMsg = JCAT_Language::Sentence("连接失败：\r\n\r\n%s",$sError) ;
				break ;
			}
	
			$sMsg = JCAT_Language::Sentence('连接成功！') ;
			$this->bIsConnected = true ;

		}while(0) ;
		
		
		if($sMsg)
		{
			JCAT_Gtk::MsgDlg($sMsg) ;
		}
	}
	

	
	/**
	 * what's this
	 * 
	 * @access	public
	 * @return	void
	 */
	public function IsConnected()
	{
		return $this->bIsConnected ;
	}

	/**
	 * 
	 * 
	 * @access	private
	 * @var		JCAT_DB
	 */
	private $aDB ;
	
	/**
	 * 
	 * 
	 * @access	private
	 * @var		bool
	 */
	private $bIsConnected = false ;

}

?><?
/**
 * [注意!!]
 *	以下内容由 JCAT PHP Toolbox 自动维护，手动更改的内容会被 JCAT PHP Toolbox 抹除，
 *	同时还可能破坏格式，导致 JCAT PHP Toolbox 无法正常读取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